<template>
	<div v-loading.fullscreen.lock="fullscreenLoading" element-loading-text="Efforts to generate PDF" class="main">
		<div v-html="pdfData"></div>
	</div>
</template>



<script>
	import {
		getUserData,
		DeleteDataBase
	} from "@/utils/IndexedDB.js";
	export default {
		data() {
			return {
				pdfData: "",
				fullscreenLoading: true,

			};
		},
		created() {
			this.initData();

		},
		methods: {
			initData() {
				getUserData("HtmlBase", "infoBase", 0)
					.then((_) => {
						console.log(_.html)
						
						this.pdfData = _.html;
						let getIP = ''
						if(sessionStorage.getItem('getIP')){
							getIP = sessionStorage.getItem('getIP')
						}
						setTimeout(() => {
							this.fullscreenLoading = false;
							DeleteDataBase('HtmlBase', 'infoBase')
						}, 2000);
						setTimeout(() => {
							if(sessionStorage.getItem('getType')){
								const originalTitle = document.title; // 保存原始标题
								console.log(getIP,888)
								document.title = getIP + "+智能报告.pdf"; // 设置新标题
								
								window.print(); // 触发打印
							}else{
								const originalTitle = document.title; // 保存原始标题
								console.log(getIP,888)
								document.title = getIP + "+一键巡检报告.pdf"; // 设置新标题
								
								window.print(); // 触发打印
							}

							// 打印后恢复原始标题（使用延时确保生效）
							setTimeout(() => {
								document.title = originalTitle;
							}, 500);
						}, 2600);
						setTimeout(() => {
							this.pdfData = '';
							window.close()
							sessionStorage.removeItem('getType')
						}, 2700)
					})
					.catch((_) => {})
					.finally((_) => {});
			},
		},
	};
</script>

<style lang="scss" scoped>
	.main-article {
		padding: 20px;
		margin: 0 auto;
		display: block;
		width: 740px;
		background: #fff;
		height: 3000px;
	}

	.article__heading {
		position: relative;
		padding: 0 0 20px;
		overflow: hidden;
	}

	.article__heading__title {
		display: block;
		display: -webkit-box;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 2;
		line-clamp: 2;
		word-wrap: break-word;
		overflow-wrap: break-word;
		font-size: 32px;
		line-height: 48px;
		font-weight: 600;
		color: #333;
		overflow: hidden;
	}

	.node-article-content {
		margin: 20px 0 0;

		background-color: #333;
		//   @include clearfix;
		font-size: 16px;
		color: #333;
		letter-spacing: 0.5px;
		line-height: 28px;
		margin-bottom: 30px;
		font-family: medium-content-serif-font, Georgia, Cambria, "Times New Roman",
			Times, serif;

		.node-article-content> :last-child {
			margin-bottom: 0;
		}

		//   b,
		//   strong {
		//     font-weight: inherit;
		//     font-weight: bolder;
		//   }

		//   img {
		//     max-width: 100%;
		//     display: block;
		//     margin: 0 auto;
		//   }

		//   p {
		//     font-weight: 400;
		//     font-style: normal;
		//     font-size: 21px;
		//     line-height: 1.58;
		//     letter-spacing: -0.003em;
		//   }

		//   ul {
		//     margin-bottom: 30px;
		//   }

		//   li {
		//     --x-height-multiplier: 0.375;
		//     --baseline-multiplier: 0.17;

		//     letter-spacing: 0.01rem;
		//     font-weight: 400;
		//     font-style: normal;
		//     font-size: 21px;
		//     line-height: 1.58;
		//     letter-spacing: -0.003em;
		//     margin-left: 30px;
		//     margin-bottom: 14px;
		//   }

		//   a {
		//     text-decoration: none;
		//     background-repeat: repeat-x;
		//     background-image: linear-gradient(
		//       to right,
		//       rgba(0, 0, 0, 0.84) 100%,
		//       rgba(0, 0, 0, 0) 0
		//     );
		//     background-size: 1px 1px;
		//     background-position: 0 calc(1em + 1px);
		//     padding: 0 6px;
		//   }

		.node-article-content code {
			background: rgba(0, 0, 0, 0.05);
			padding: 3px 4px;
			margin: 0 2px;
			font-size: 16px;
			display: inline-block;
		}

		//   img {
		//     border: 0;
		//   }

		//   /* 解决 IE6-7 图片缩放锯齿问题 */
		//   img {
		//     -ms-interpolation-mode: bicubic;
		//   }

		//   blockquote {
		//     --x-height-multiplier: 0.375;
		//     --baseline-multiplier: 0.17;
		//     font-family: medium-content-serif-font, Georgia, Cambria, "Times New Roman",
		//       Times, serif;
		//     letter-spacing: 0.01rem;
		//     font-weight: 400;
		//     font-style: italic;
		//     font-size: 21px;
		//     line-height: 1.58;
		//     letter-spacing: -0.003em;
		//     border-left: 3px solid rgba(0, 0, 0, 0.84);
		//     padding-left: 20px;
		//     margin-left: -23px;
		//     padding-bottom: 2px;
		//   }

		.node-article-content a {
			text-decoration: none;
		}

		//   h2,
		//   h3,
		//   h4 {
		//     font-size: 34px;
		//     line-height: 1.15;
		//     letter-spacing: -0.015em;
		//     margin: 53px 0 0;
		//   }

		//   h4 {
		//     font-size: 26px;
		//   }
	}

	.main {
		background: #333;
	}
</style>